;; LAMP环境



(use-modules
 (gnu)
 (gnu packages)
 (gnu packages bash)
 (gnu packages busybox)
 )

(use-service-modules
 base
 ssh 
 databases
 web
 )


(operating-system
  (host-name "lamp")
  (timezone "UTC")
  (locale "en_US.utf8")

  
  ;; 引导(忽略)
  (bootloader (bootloader-configuration
	       (bootloader grub-bootloader)
	       (target "does-not-matter")))
  
    ;; 文件系统(忽略)
  (file-systems (list (file-system
			(device "does-not-matter")
			(mount-point "/")
			(type "does-not-matter"))))

  ;; 账户
  (users
   (append
    (list
     (user-account
      (name "lamp")
      (comment "user")
      (group "users")
      (uid 41253)
      (supplementary-groups '("www-data"))
      )
     )
    %base-user-accounts))

  (groups
   (append
    (list
     (user-group
      (name "www-data")
      (id 41254)) ;; 用于拷贝文件到网站目录
     )
    %base-groups))


  ;; 全局安装的包
  (packages
   (map
    specification->package
    (list
     ;; shell
     "bash"
     
     ;; 工具集
     "busybox"

     ;; Mysql 客户端工具
     "mysql"

     ;; http 测试工具
     "w3m"
     "curl"
     "wget"

     ;; 增量文件复制工具
     "rsync"

     ;; 编辑器
     "vim"
     
     ;; ssl证书
     "nss-certs"
     )
    )
   )

  ;; 服务
  (services
   (list

    ;; 脚本兼容
    (service special-files-service-type
	     `(("/bin/sh" ,(file-append bash "/bin/sh"))
	       ("/usr/bin/env" ,(file-append coreutils "/bin/env"))))

        ;; ssh
    (service openssh-service-type
	     (openssh-configuration
	      (port-number 43223)
	      (permit-root-login #f)
	      (password-authentication? #f)
	      (public-key-authentication? #t)))
    
    ;; log 记录服务
    (syslog-service)

    ;; 网络
    (service static-networking-service-type
	     (list (static-networking (interface "lo")
				      (ip "127.0.0.1")
				      (requirement '())
				      (provision '(loopback networking)))))

    ;; mysql
    (service mysql-service-type
	     (mysql-configuration
	      (port 63306)))

    ;; apache
    (service httpd-service-type
	     (httpd-configuration
	      (config (httpd-config-file
		       (server-name "localhost")
		       (document-root "/srv/www/default")
		       (modules (cons*
				 (httpd-module
				  (name "proxy_module")
				  (file "modules/mod_proxy.so"))
				 (httpd-module
				  (name "proxy_fcgi_module")
				  (file "modules/mod_proxy_fcgi.so"))
				 %default-httpd-modules))
		       (extra-config
			(list
			 "\
                         <FilesMatch \\.php$>
                         SetHandler \"proxy:unix:/var/run/php-fpm.sock|fcgi://localhost/\"
                         </FilesMatch>"
			 )
			)
		       )
		      )
	      )
	     )

    ;; php-fpm
    (service php-fpm-service-type
	     (php-fpm-configuration
	      (socket "/var/run/php-fpm.sock")
	      (socket-group "httpd")
	      )
	     )
    )
   )
  )
